package com.drcurd.service.impl;

import com.drcurd.entity.Product;
import com.drcurd.dto.ProductQueryDTO;
import com.drcurd.mapper.ProductMapper;
import com.drcurd.service.ProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 产品服务实现类
 */
@Service
public class ProductServiceImpl implements ProductService {
    
    @Autowired
    private ProductMapper productMapper;
    
    @Override
    public PageInfo<Product> getProductList(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Product> list = productMapper.selectAll();
        return new PageInfo<>(list);
    }
    
    @Override
    public PageInfo<Product> getProductListByCondition(ProductQueryDTO queryDTO) {
        PageHelper.startPage(queryDTO.getPageNum(), queryDTO.getPageSize());
        List<Product> list = productMapper.selectByCondition(queryDTO);
        return new PageInfo<>(list);
    }
    
    @Override
    public List<Product> getAllProducts() {
        return productMapper.selectAll();
    }
    
    @Override
    public Product getProductById(Long id) {
        return productMapper.selectById(id);
    }
    
    @Override
    public boolean addProduct(Product product) {
        return productMapper.insert(product) > 0;
    }
    
    @Override
    public boolean updateProduct(Product product) {
        return productMapper.update(product) > 0;
    }
    
    @Override
    public boolean deleteProduct(Long id) {
        return productMapper.deleteById(id) > 0;
    }
} 